package com.zdb.n1.repository;

import com.zdb.n1.entity.HealthData;
import com.zdb.n1.entity.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
import java.util.Optional;

@Repository
public interface HealthDataRepository extends JpaRepository<HealthData, Long> {

    List<HealthData> findByUserOrderByRecordDateDesc(User user);

    Page<HealthData> findByUserOrderByRecordDateDesc(User user, Pageable pageable);

    List<HealthData> findByUserAndRecordDateBetweenOrderByRecordDateDesc(
            User user, Date startDate, Date endDate);

    @Query("SELECT h FROM HealthData h WHERE h.user = ?1 ORDER BY h.recordDate DESC LIMIT 1")
    Optional<HealthData> findLatestByUser(User user);
} 